/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mamayukero.problem.environment.component;

import java.awt.Point;
import java.util.ArrayList;

public class Vendor extends Warehouse {
        public char name;
        public int ID;
        
        
	/**
	 * Straight line distance to factory
	 */
	private int straigthLine;
        	
	public Vendor()
	{
		ID = 0;
		name = ' ';
		location = new Point(0,0);
                machines = new ArrayList<Machine>();
	}
	
	public Vendor(int ID, char pName, Point p)
	{
		this.ID = ID;
		name = pName;
		location = p;
                machines = new ArrayList<Machine>();
	}
	
	/**
	 * 
	 * @param f the factory 
	 * @return integer straight line distance to the factory
	 */
	private int calcStraightLine(Factory f)
	{
		int xLength = (int) Math.pow(Math.abs(location.x - f.getLocation().x), 2);
		int yLength = (int) Math.pow(Math.abs(location.y - f.getLocation().y), 2);
		return (int) Math.sqrt(xLength+yLength);
	}

	public void setStraightLine(Factory f)
	{
		straigthLine = calcStraightLine(f);
	}
	
	public int getStraightLine()
	{
		return straigthLine;
	}

        @Override
        public String toString() {
            StringBuilder result = new StringBuilder("[" + name + "] (" + location.x + "," + location.y + ")");
            for (Machine m : machines) {
                result.append(" [");
                result.append(m.type);
                result.append("]");
            }
            return result.toString();
        }
        
        public static Vendor findVendorwName(ArrayList<Vendor> av, char c) {
            for (Vendor v : av) {
                if (v.name == c) return v;
            }
            return null;
        }
}
